/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import entities.Manager;
import java.util.Vector;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author MinhDuc
 */
public class ManagerTableModel extends AbstractTableModel {

    public static final int MANAGERID_INDEX = 0;
    public static final int FULLNAME_INDEX = 1;
    public static final int USERNAME_INDEX = 2;
    public static final int PASSWORD_INDEX = 3;
    private String[] columnNames = {"Manger ID", "Full Name", "User Name", "Password"};
    Vector<Manager> data;

    public ManagerTableModel(Vector<Manager> data) {
        this.data = data;
    }

    @Override
    public int getRowCount() {
        return data.size();
    }

    @Override
    public int getColumnCount() {
        return columnNames.length;
    }

    @Override
    public String getColumnName(int column) {
        return columnNames[column];
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        Manager manager = (Manager) data.get(rowIndex);
        switch (columnIndex) {
            case MANAGERID_INDEX:
                return manager.getManagerID();
            case FULLNAME_INDEX:
                return manager.getFullName();
            case USERNAME_INDEX:
                return manager.getUserName();
            case PASSWORD_INDEX:
                return manager.getPassword();
            default:
                return new Object();
        }
    }

    @Override
    public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
        Manager manager = (Manager) data.get(rowIndex);
        switch (columnIndex) {
            case MANAGERID_INDEX:
                manager.setManagerID(Integer.valueOf(String.valueOf(aValue)));
                break;
            case FULLNAME_INDEX:
                manager.setFullName(String.valueOf(aValue));
                break;
            case USERNAME_INDEX:
                manager.setUserName(String.valueOf(aValue));
                break;
            case PASSWORD_INDEX:
                manager.setPassword(String.valueOf(aValue));
                break;
            default:
                System.out.println("INVALID INDEX");
        }
        fireTableCellUpdated(rowIndex, columnIndex);
    }

    @Override
    public Class<?> getColumnClass(int columnIndex) {
        switch (columnIndex) {
            case MANAGERID_INDEX:
                return Integer.class;
            case FULLNAME_INDEX:
                return String.class;
            case USERNAME_INDEX:
                return String.class;
            case PASSWORD_INDEX:
                return String.class;
            default:
                return Object.class;
        }
    }

    public void setData(Vector<Manager> data) {
        this.data = data;
    }
}
